// Copyright 2022 marcello<volibearw@gmail.com>. All rights reserved.

package main

import (
	"fmt"

	"github.com/spf13/pflag"
)

func usage() {
	fmt.Println("Usage: gen-model-protobuf-tools [OPTS]")
	fmt.Println("Options:")
	pflag.PrintDefaults()
}

func main() {

	var cliParam = &CLIParam{}

	pflag.StringVar(&cliParam.Host, "host", "127.0.0.1", "")
	pflag.UintVar(&cliParam.Port, "port", 3306, "")
	pflag.StringVar(&cliParam.User, "user", "root", "")
	pflag.StringVar(&cliParam.Passwd, "passwd", "", "")
	pflag.StringVar(&cliParam.Schema, "schema", "", "")
	pflag.StringVar(&cliParam.Charset, "charset", "", "")

	pflag.BoolVar(&cliParam.Model, "model", true, "model开关")
	pflag.StringVar(&cliParam.ModelOut, "model-out", "./entity", "model输出目录")
	pflag.StringVar(&cliParam.ModelFilePackage, "model-package", "entity", "model file package name")

	pflag.BoolVar(&cliParam.ModelUseGorm, "model-user-gorm", true, "使用gorm")
	pflag.BoolVar(&cliParam.ModelIncludeGormModel, "model-gorm-model", true, "包含gorm.Model开关")
	pflag.BoolVar(&cliParam.ModelIncludeProtoConvert, "model-to-proto", true, "转换proto开关")
	pflag.StringVar(&cliParam.ModelImportPbPath, "model-import-pb-path", "", "import protobuf path")

	pflag.BoolVar(&cliParam.ModelOverwrite, "model-overwrite", false, "自动覆盖旧文件")

	pflag.BoolVar(&cliParam.Proto, "proto", false, "proto开关")
	pflag.StringVar(&cliParam.ProtoOut, "proto-out", "./pb", "proto输出目录")
	pflag.StringVar(&cliParam.ProtoPackage, "proto-package", "pb", "proto package")
	pflag.StringVar(&cliParam.ProtoOptionGoPackage, "proto-option-go-package", ".", "proto go_option package")
	pflag.Parse()

	if cliParam.Proto == false && cliParam.Proto {
		usage()
		return
	}

	if cliParam.Schema == "" {
		usage()
		return
	}

	//b, _ := json.Marshal(cliParam)
	//fmt.Println(string(b))
	//return

	test(cliParam)
}
